clear all
cap log use

set maxvar 30000

use "JIR-Sep2024"

merge m:1 p using "insurance.dta"
drop _merge


drop if byr_spouse==.
gen age_spouse=year-byr_spouse
gen age_spouse2=age_spouse^2


gen age_wife=age if parent==1&male==0
replace age_wife=age_spouse if parent==1&male==1

gen age_hus=age if parent==1&male==1
replace age_hus=age_spouse if parent==1&male==0

*age restricions on parents
keep if age>49&age_spouse>49
keep if parent==1

*remove obs with independent children who is below 18
gen indp_n=a68a
replace indp_n=a68b
replace indp_n=. if indp_n>20

gen withind=1 if indp_n>0&indp_n<=20
replace withind=0 if indp_n==0

drop if withind==1

*Keep if reside in hukou place
keep if hukou_local==1|hukou_local==2


gen edu_spouse=1 if a72>=1&a72<=4
replace edu_spouse=2 if a72>=5&a72<=8
replace edu_spouse=3 if a72>=9&a72<=14


gen byr_wife=byr if male==0
replace byr_wife=byr_spouse if male==1

gen ins_h=1 if hinsurance==1|hinsurance_c==1
replace ins_h=0 if hinsurance==0&hinsurance_c==0

gen ins_s=1 if sinsurance==1|sinsurance_c==1
replace ins_s=0 if sinsurance==0&sinsurance_c==0

*remove obs from minority ethnic groups
keep if han==1

drop if mari<0

*recode hukou type
gen rural_hk=1 if hukou_nong==1
replace rural_hk=1 if hukou_nong==3&year==2010
replace rural_hk=1 if hukou_nong==3&year==2013
replace rural_hk=1 if hukou_nong==3&year==2015
replace rural_hk=1 if hukou_nong==3&year==2017
replace rural_hk=1 if hukou_nong==3&year==2018
replace rural_hk=0 if hukou_nong==3&year==2012
replace rural_hk=0 if hukou_nong==4&year==2012
replace rural_hk=0 if hukou_nong==4&year==2010
replace rural_hk=0 if hukou_nong==4&year==2013
replace rural_hk=0 if hukou_nong==4&year==2015
replace rural_hk=0 if hukou_nong==4&year==2017
replace rural_hk=0 if hukou_nong==4&year==2018
replace rural_hk=0 if hukou_nong==2

*internet use frequency
gen interf=a285 if a285>=1&a285<=5


***abnormal BMI
gen height=a13 if a13>0&a13<200
gen w=a14 if a14>0&a14<300

gen bmi=0.5*w/((height/100)^2)

gen abnormal1=1 if bmi!=.&bmi>=25
replace abnormal1=1 if bmi!=.&bmi<18.5
replace abnormal1=0 if bmi>=18.5&bmi<25


*recode marital status
gen mari=1 if mari_raw==3
replace mari=1 if mari_raw==4
replace mari=2 if mari_raw==2
replace mari=3 if mari_raw==5

gen age3=age^3
gen age_spouse3 =age_spouse^3

gen rely_child1=1 if a41==2
replace rely_child1=0 if a41==1|a41==3|a41==4

gen manstronger= a422 if a422>=1&a422<=5

gen housen=a65 if a65>=0&a65<90


label var sinsurance_c "private pension"
label var hinsurance_c "private health insurance"
label var ins_c "private insurance"
label var sinsurance "public pension"
label var hinsurance "public health insurance"
label var p "province"
label var rural_hk "whether hold rural hukou"
label var rinc_hh1 "household income (log)"
label var sah "self-assessed health"
label var children_have "number of children"
label var rely_child1 "reliance on children for old-age"
label var manstronger "men superiority"
label var housen "number of houses"
label var interf "internet use frequency"
label var dffp_wife8268 "PEI"







***************************************
**************regressions**************
***************************************



********************************
******IV probit*****************Table 6-Panel A
********************************



ivprobit sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah  , first vce(clu p) 
est store pro_sc
gen sample_sc=1 if e(sample)==1
margins, dydx(children_have)  predict(pr)   


ivprobit hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   , first vce(clu p) 
est store pro_hc
gen sample_hc=1 if e(sample)==1
margins, dydx(children_have) predict(pr)     

ivprobit ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah  , first vce(clu p)
est store pro_c
gen sample_c=1 if e(sample)==1
margins, dydx(children_have) predict(pr)   



ivprobit sinsurance (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah  , first vce(clu p) 
est store pro_s
gen sample_s=1 if e(sample)==1
margins, dydx(children_have)  predict(pr) 


ivprobit hinsurance (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   , first vce(clu p) 
est store pro_h
gen sample_h=1 if e(sample)==1
margins, dydx(children_have)  predict(pr)   





*************************
*******statistics********Table 2
*************************

sum sinsurance_c if sample_sc==1
sum hinsurance_c if sample_hc==1
sum ins_c if sample_c==1

*Table 2 used
sum  children_have  age age_spouse rural_hk male edu edu_spouse mari rinc_hh1  sah if sample_sc==1|sample_hc==1|sample_c==1


gen totalsample=1  if sample_sc==1|sample_hc==1|sample_c==1

sum children_have if totalsample==1
sum age if totalsample==1
sum age_spouse if totalsample==1
sum rinc_hh1 if totalsample==1

tab edu if totalsample==1
tab edu_spouse if totalsample==1
tab mari if totalsample==1
tab sah if totalsample==1




 
************************************
*****Linear Probability Model*******Table 3
************************************


ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_sc==1, first clu(p) 
est store iv_s_c
estat firststage,forcenonrobust

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_hc==1, first clu(p)
est store iv_h_c
estat firststage,forcenonrobust

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_c==1, first clu(p) 
est store iv_c
estat firststage,forcenonrobust

ivregress 2sls sinsurance (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_s==1, first clu(p) 
est store iv_s
estat firststage,forcenonrobust

ivregress 2sls hinsurance (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_h==1, first clu(p)
est store iv_h
estat firststage,forcenonrobust



************************
*********Table 4********
************************

*column 1:

reg  rely_child1 dffp_wife8268 male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 

*column 3

reg manstronger dffp_wife8268 male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,  vce(clu p) //-

*Column 2 # of house

reg  rely_child1 c.housen##c.dffp_wife8268   male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 

*Column 4 # of house 
reg  manstronger c.housen##c.dffp_wife8268   male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 





************************
*********Table 5********
************************



*Outcome variables
gen penetration=penetration_life2018 if year==2018
replace penetration=penetration_life2017 if year==2017
replace penetration=penetration_life2015 if year==2015
replace penetration=penetration_life2013 if year==2013
replace penetration=penetration_life2012 if year==2012
replace penetration=penetration_life2010 if year==2010

gen density=density_life2018 if year==2018
replace density=density_life2017 if year==2017
replace density=density_life2015 if year==2015
replace density=density_life2013 if year==2013
replace density=density_life2012 if year==2012
replace density=density_life2010 if year==2010

gen rdensity=density*base/cpi

bys p year: gen nn=_n


**aggregate policy index 
egen index_jing=rowtotal (dAFR_8268_jing15 dAFR_8268_jing16 dAFR_8268_jing17 dAFR_8268_jing18 dAFR_8268_jing19 dAFR_8268_jing20 dAFR_8268_jing21 dAFR_8268_jing22 dAFR_8268_jing23 dAFR_8268_jing24 dAFR_8268_jing25 dAFR_8268_jing26 dAFR_8268_jing27 dAFR_8268_jing28 dAFR_8268_jing29 dAFR_8268_jing30 dAFR_8268_jing31 dAFR_8268_jing32 dAFR_8268_jing33 dAFR_8268_jing34 dAFR_8268_jing35 dAFR_8268_jing36 dAFR_8268_jing37 dAFR_8268_jing38 dAFR_8268_jing39 dAFR_8268_jing40 dAFR_8268_jing41 dAFR_8268_jing42 dAFR_8268_jing43 dAFR_8268_jing44 dAFR_8268_jing45 dAFR_8268_jing46 dAFR_8268_jing47 dAFR_8268_jing48 dAFR_8268_jing49)


egen index_jin=rowtotal (dAFR_8268_jin15 dAFR_8268_jin16 dAFR_8268_jin17 dAFR_8268_jin18 dAFR_8268_jin19 dAFR_8268_jin20 dAFR_8268_jin21 dAFR_8268_jin22 dAFR_8268_jin23 dAFR_8268_jin24 dAFR_8268_jin25 dAFR_8268_jin26 dAFR_8268_jin27 dAFR_8268_jin28 dAFR_8268_jin29 dAFR_8268_jin30 dAFR_8268_jin31 dAFR_8268_jin32 dAFR_8268_jin33 dAFR_8268_jin34 dAFR_8268_jin35 dAFR_8268_jin36 dAFR_8268_jin37 dAFR_8268_jin38 dAFR_8268_jin39 dAFR_8268_jin40 dAFR_8268_jin41 dAFR_8268_jin42 dAFR_8268_jin43 dAFR_8268_jin44 dAFR_8268_jin45 dAFR_8268_jin46 dAFR_8268_jin47 dAFR_8268_jin48 dAFR_8268_jin49)


egen index_ji=rowtotal (dAFR_8268_ji15 dAFR_8268_ji16 dAFR_8268_ji17 dAFR_8268_ji18 dAFR_8268_ji19 dAFR_8268_ji20 dAFR_8268_ji21 dAFR_8268_ji22 dAFR_8268_ji23 dAFR_8268_ji24 dAFR_8268_ji25 dAFR_8268_ji26 dAFR_8268_ji27 dAFR_8268_ji28 dAFR_8268_ji29 dAFR_8268_ji30 dAFR_8268_ji31 dAFR_8268_ji32 dAFR_8268_ji33 dAFR_8268_ji34 dAFR_8268_ji35 dAFR_8268_ji36 dAFR_8268_ji37 dAFR_8268_ji38 dAFR_8268_ji39 dAFR_8268_ji40 dAFR_8268_ji41 dAFR_8268_ji42 dAFR_8268_ji43 dAFR_8268_ji44 dAFR_8268_ji45 dAFR_8268_ji46 dAFR_8268_ji47 dAFR_8268_ji48 dAFR_8268_ji49)


egen index_shan=rowtotal (dAFR_8268_shan15 dAFR_8268_shan16 dAFR_8268_shan17 dAFR_8268_shan18 dAFR_8268_shan19 dAFR_8268_shan20 dAFR_8268_shan21 dAFR_8268_shan22 dAFR_8268_shan23 dAFR_8268_shan24 dAFR_8268_shan25 dAFR_8268_shan26 dAFR_8268_shan27 dAFR_8268_shan28 dAFR_8268_shan29 dAFR_8268_shan30 dAFR_8268_shan31 dAFR_8268_shan32 dAFR_8268_shan33 dAFR_8268_shan34 dAFR_8268_shan35 dAFR_8268_shan36 dAFR_8268_shan37 dAFR_8268_shan38 dAFR_8268_shan39 dAFR_8268_shan40 dAFR_8268_shan41 dAFR_8268_shan42 dAFR_8268_shan43 dAFR_8268_shan44 dAFR_8268_shan45 dAFR_8268_shan46 dAFR_8268_shan47 dAFR_8268_shan48 dAFR_8268_shan49)


egen index_inner=rowtotal (dAFR_8268_inner15 dAFR_8268_inner16 dAFR_8268_inner17 dAFR_8268_inner18 dAFR_8268_inner19 dAFR_8268_inner20 dAFR_8268_inner21 dAFR_8268_inner22 dAFR_8268_inner23 dAFR_8268_inner24 dAFR_8268_inner25 dAFR_8268_inner26 dAFR_8268_inner27 dAFR_8268_inner28 dAFR_8268_inner29 dAFR_8268_inner30 dAFR_8268_inner31 dAFR_8268_inner32 dAFR_8268_inner33 dAFR_8268_inner34 dAFR_8268_inner35 dAFR_8268_inner36 dAFR_8268_inner37 dAFR_8268_inner38 dAFR_8268_inner39 dAFR_8268_inner40 dAFR_8268_inner41 dAFR_8268_inner42 dAFR_8268_inner43 dAFR_8268_inner44 dAFR_8268_inner45 dAFR_8268_inner46 dAFR_8268_inner47 dAFR_8268_inner48 dAFR_8268_inner49)


egen index_zhe=rowtotal (dAFR_8268_zhe15 dAFR_8268_zhe16 dAFR_8268_zhe17 dAFR_8268_zhe18 dAFR_8268_zhe19 dAFR_8268_zhe20 dAFR_8268_zhe21 dAFR_8268_zhe22 dAFR_8268_zhe23 dAFR_8268_zhe24 dAFR_8268_zhe25 dAFR_8268_zhe26 dAFR_8268_zhe27 dAFR_8268_zhe28 dAFR_8268_zhe29 dAFR_8268_zhe30 dAFR_8268_zhe31 dAFR_8268_zhe32 dAFR_8268_zhe33 dAFR_8268_zhe34 dAFR_8268_zhe35 dAFR_8268_zhe36 dAFR_8268_zhe37 dAFR_8268_zhe38 dAFR_8268_zhe39 dAFR_8268_zhe40 dAFR_8268_zhe41 dAFR_8268_zhe42 dAFR_8268_zhe43 dAFR_8268_zhe44 dAFR_8268_zhe45 dAFR_8268_zhe46 dAFR_8268_zhe47 dAFR_8268_zhe48 dAFR_8268_zhe49)


egen index_su=rowtotal (dAFR_8268_su15 dAFR_8268_su16 dAFR_8268_su17 dAFR_8268_su18 dAFR_8268_su19 dAFR_8268_su20 dAFR_8268_su21 dAFR_8268_su22 dAFR_8268_su23 dAFR_8268_su24 dAFR_8268_su25 dAFR_8268_su26 dAFR_8268_su27 dAFR_8268_su28 dAFR_8268_su29 dAFR_8268_su30 dAFR_8268_su31 dAFR_8268_su32 dAFR_8268_su33 dAFR_8268_su34 dAFR_8268_su35 dAFR_8268_su36 dAFR_8268_su37 dAFR_8268_su38 dAFR_8268_su39 dAFR_8268_su40 dAFR_8268_su41 dAFR_8268_su42 dAFR_8268_su43 dAFR_8268_su44 dAFR_8268_su45 dAFR_8268_su46 dAFR_8268_su47 dAFR_8268_su48 dAFR_8268_su49)


egen index_hu=rowtotal (dAFR_8268_hu15 dAFR_8268_hu16 dAFR_8268_hu17 dAFR_8268_hu18 dAFR_8268_hu19 dAFR_8268_hu20 dAFR_8268_hu21 dAFR_8268_hu22 dAFR_8268_hu23 dAFR_8268_hu24 dAFR_8268_hu25 dAFR_8268_hu26 dAFR_8268_hu27 dAFR_8268_hu28 dAFR_8268_hu29 dAFR_8268_hu30 dAFR_8268_hu31 dAFR_8268_hu32 dAFR_8268_hu33 dAFR_8268_hu34 dAFR_8268_hu35 dAFR_8268_hu36 dAFR_8268_hu37 dAFR_8268_hu38 dAFR_8268_hu39 dAFR_8268_hu40 dAFR_8268_hu41 dAFR_8268_hu42 dAFR_8268_hu43 dAFR_8268_hu44 dAFR_8268_hu45 dAFR_8268_hu46 dAFR_8268_hu47 dAFR_8268_hu48 dAFR_8268_hu49)


egen index_hei=rowtotal (dAFR_8268_hei15 dAFR_8268_hei16 dAFR_8268_hei17 dAFR_8268_hei18 dAFR_8268_hei19 dAFR_8268_hei20 dAFR_8268_hei21 dAFR_8268_hei22 dAFR_8268_hei23 dAFR_8268_hei24 dAFR_8268_hei25 dAFR_8268_hei26 dAFR_8268_hei27 dAFR_8268_hei28 dAFR_8268_hei29 dAFR_8268_hei30 dAFR_8268_hei31 dAFR_8268_hei32 dAFR_8268_hei33 dAFR_8268_hei34 dAFR_8268_hei35 dAFR_8268_hei36 dAFR_8268_hei37 dAFR_8268_hei38 dAFR_8268_hei39 dAFR_8268_hei40 dAFR_8268_hei41 dAFR_8268_hei42 dAFR_8268_hei43 dAFR_8268_hei44 dAFR_8268_hei45 dAFR_8268_hei46 dAFR_8268_hei47 dAFR_8268_hei48 dAFR_8268_hei49)


egen index_jilin=rowtotal (dAFR_8268_jilin15 dAFR_8268_jilin16 dAFR_8268_jilin17 dAFR_8268_jilin18 dAFR_8268_jilin19 dAFR_8268_jilin20 dAFR_8268_jilin21 dAFR_8268_jilin22 dAFR_8268_jilin23 dAFR_8268_jilin24 dAFR_8268_jilin25 dAFR_8268_jilin26 dAFR_8268_jilin27 dAFR_8268_jilin28 dAFR_8268_jilin29 dAFR_8268_jilin30 dAFR_8268_jilin31 dAFR_8268_jilin32 dAFR_8268_jilin33 dAFR_8268_jilin34 dAFR_8268_jilin35 dAFR_8268_jilin36 dAFR_8268_jilin37 dAFR_8268_jilin38 dAFR_8268_jilin39 dAFR_8268_jilin40 dAFR_8268_jilin41 dAFR_8268_jilin42 dAFR_8268_jilin43 dAFR_8268_jilin44 dAFR_8268_jilin45 dAFR_8268_jilin46 dAFR_8268_jilin47 dAFR_8268_jilin48 dAFR_8268_jilin49)


egen index_liao=rowtotal (dAFR_8268_liao15 dAFR_8268_liao16 dAFR_8268_liao17 dAFR_8268_liao18 dAFR_8268_liao19 dAFR_8268_liao20 dAFR_8268_liao21 dAFR_8268_liao22 dAFR_8268_liao23 dAFR_8268_liao24 dAFR_8268_liao25 dAFR_8268_liao26 dAFR_8268_liao27 dAFR_8268_liao28 dAFR_8268_liao29 dAFR_8268_liao30 dAFR_8268_liao31 dAFR_8268_liao32 dAFR_8268_liao33 dAFR_8268_liao34 dAFR_8268_liao35 dAFR_8268_liao36 dAFR_8268_liao37 dAFR_8268_liao38 dAFR_8268_liao39 dAFR_8268_liao40 dAFR_8268_liao41 dAFR_8268_liao42 dAFR_8268_liao43 dAFR_8268_liao44 dAFR_8268_liao45 dAFR_8268_liao46 dAFR_8268_liao47 dAFR_8268_liao48 dAFR_8268_liao49)


egen index_wan=rowtotal (dAFR_8268_wan15 dAFR_8268_wan16 dAFR_8268_wan17 dAFR_8268_wan18 dAFR_8268_wan19 dAFR_8268_wan20 dAFR_8268_wan21 dAFR_8268_wan22 dAFR_8268_wan23 dAFR_8268_wan24 dAFR_8268_wan25 dAFR_8268_wan26 dAFR_8268_wan27 dAFR_8268_wan28 dAFR_8268_wan29 dAFR_8268_wan30 dAFR_8268_wan31 dAFR_8268_wan32 dAFR_8268_wan33 dAFR_8268_wan34 dAFR_8268_wan35 dAFR_8268_wan36 dAFR_8268_wan37 dAFR_8268_wan38 dAFR_8268_wan39 dAFR_8268_wan40 dAFR_8268_wan41 dAFR_8268_wan42 dAFR_8268_wan43 dAFR_8268_wan44 dAFR_8268_wan45 dAFR_8268_wan46 dAFR_8268_wan47 dAFR_8268_wan48 dAFR_8268_wan49)


egen index_min=rowtotal (dAFR_8268_min15 dAFR_8268_min16 dAFR_8268_min17 dAFR_8268_min18 dAFR_8268_min19 dAFR_8268_min20 dAFR_8268_min21 dAFR_8268_min22 dAFR_8268_min23 dAFR_8268_min24 dAFR_8268_min25 dAFR_8268_min26 dAFR_8268_min27 dAFR_8268_min28 dAFR_8268_min29 dAFR_8268_min30 dAFR_8268_min31 dAFR_8268_min32 dAFR_8268_min33 dAFR_8268_min34 dAFR_8268_min35 dAFR_8268_min36 dAFR_8268_min37 dAFR_8268_min38 dAFR_8268_min39 dAFR_8268_min40 dAFR_8268_min41 dAFR_8268_min42 dAFR_8268_min43 dAFR_8268_min44 dAFR_8268_min45 dAFR_8268_min46 dAFR_8268_min47 dAFR_8268_min48 dAFR_8268_min49)


egen index_gan=rowtotal (dAFR_8268_gan15 dAFR_8268_gan16 dAFR_8268_gan17 dAFR_8268_gan18 dAFR_8268_gan19 dAFR_8268_gan20 dAFR_8268_gan21 dAFR_8268_gan22 dAFR_8268_gan23 dAFR_8268_gan24 dAFR_8268_gan25 dAFR_8268_gan26 dAFR_8268_gan27 dAFR_8268_gan28 dAFR_8268_gan29 dAFR_8268_gan30 dAFR_8268_gan31 dAFR_8268_gan32 dAFR_8268_gan33 dAFR_8268_gan34 dAFR_8268_gan35 dAFR_8268_gan36 dAFR_8268_gan37 dAFR_8268_gan38 dAFR_8268_gan39 dAFR_8268_gan40 dAFR_8268_gan41 dAFR_8268_gan42 dAFR_8268_gan43 dAFR_8268_gan44 dAFR_8268_gan45 dAFR_8268_gan46 dAFR_8268_gan47 dAFR_8268_gan48 dAFR_8268_gan49)


egen index_lu=rowtotal (dAFR_8268_lu15 dAFR_8268_lu16 dAFR_8268_lu17 dAFR_8268_lu18 dAFR_8268_lu19 dAFR_8268_lu20 dAFR_8268_lu21 dAFR_8268_lu22 dAFR_8268_lu23 dAFR_8268_lu24 dAFR_8268_lu25 dAFR_8268_lu26 dAFR_8268_lu27 dAFR_8268_lu28 dAFR_8268_lu29 dAFR_8268_lu30 dAFR_8268_lu31 dAFR_8268_lu32 dAFR_8268_lu33 dAFR_8268_lu34 dAFR_8268_lu35 dAFR_8268_lu36 dAFR_8268_lu37 dAFR_8268_lu38 dAFR_8268_lu39 dAFR_8268_lu40 dAFR_8268_lu41 dAFR_8268_lu42 dAFR_8268_lu43 dAFR_8268_lu44 dAFR_8268_lu45 dAFR_8268_lu46 dAFR_8268_lu47 dAFR_8268_lu48 dAFR_8268_lu49)


egen index_henan=rowtotal (dAFR_8268_henan15 dAFR_8268_henan16 dAFR_8268_henan17 dAFR_8268_henan18 dAFR_8268_henan19 dAFR_8268_henan20 dAFR_8268_henan21 dAFR_8268_henan22 dAFR_8268_henan23 dAFR_8268_henan24 dAFR_8268_henan25 dAFR_8268_henan26 dAFR_8268_henan27 dAFR_8268_henan28 dAFR_8268_henan29 dAFR_8268_henan30 dAFR_8268_henan31 dAFR_8268_henan32 dAFR_8268_henan33 dAFR_8268_henan34 dAFR_8268_henan35 dAFR_8268_henan36 dAFR_8268_henan37 dAFR_8268_henan38 dAFR_8268_henan39 dAFR_8268_henan40 dAFR_8268_henan41 dAFR_8268_henan42 dAFR_8268_henan43 dAFR_8268_henan44 dAFR_8268_henan45 dAFR_8268_henan46 dAFR_8268_henan47 dAFR_8268_henan48 dAFR_8268_henan49)


egen index_e=rowtotal (dAFR_8268_e15 dAFR_8268_e16 dAFR_8268_e17 dAFR_8268_e18 dAFR_8268_e19 dAFR_8268_e20 dAFR_8268_e21 dAFR_8268_e22 dAFR_8268_e23 dAFR_8268_e24 dAFR_8268_e25 dAFR_8268_e26 dAFR_8268_e27 dAFR_8268_e28 dAFR_8268_e29 dAFR_8268_e30 dAFR_8268_e31 dAFR_8268_e32 dAFR_8268_e33 dAFR_8268_e34 dAFR_8268_e35 dAFR_8268_e36 dAFR_8268_e37 dAFR_8268_e38 dAFR_8268_e39 dAFR_8268_e40 dAFR_8268_e41 dAFR_8268_e42 dAFR_8268_e43 dAFR_8268_e44 dAFR_8268_e45 dAFR_8268_e46 dAFR_8268_e47 dAFR_8268_e48 dAFR_8268_e49)


egen index_xiang=rowtotal (dAFR_8268_xiang15 dAFR_8268_xiang16 dAFR_8268_xiang17 dAFR_8268_xiang18 dAFR_8268_xiang19 dAFR_8268_xiang20 dAFR_8268_xiang21 dAFR_8268_xiang22 dAFR_8268_xiang23 dAFR_8268_xiang24 dAFR_8268_xiang25 dAFR_8268_xiang26 dAFR_8268_xiang27 dAFR_8268_xiang28 dAFR_8268_xiang29 dAFR_8268_xiang30 dAFR_8268_xiang31 dAFR_8268_xiang32 dAFR_8268_xiang33 dAFR_8268_xiang34 dAFR_8268_xiang35 dAFR_8268_xiang36 dAFR_8268_xiang37 dAFR_8268_xiang38 dAFR_8268_xiang39 dAFR_8268_xiang40 dAFR_8268_xiang41 dAFR_8268_xiang42 dAFR_8268_xiang43 dAFR_8268_xiang44 dAFR_8268_xiang45 dAFR_8268_xiang46 dAFR_8268_xiang47 dAFR_8268_xiang48 dAFR_8268_xiang49)


egen index_yue=rowtotal (dAFR_8268_yue15 dAFR_8268_yue16 dAFR_8268_yue17 dAFR_8268_yue18 dAFR_8268_yue19 dAFR_8268_yue20 dAFR_8268_yue21 dAFR_8268_yue22 dAFR_8268_yue23 dAFR_8268_yue24 dAFR_8268_yue25 dAFR_8268_yue26 dAFR_8268_yue27 dAFR_8268_yue28 dAFR_8268_yue29 dAFR_8268_yue30 dAFR_8268_yue31 dAFR_8268_yue32 dAFR_8268_yue33 dAFR_8268_yue34 dAFR_8268_yue35 dAFR_8268_yue36 dAFR_8268_yue37 dAFR_8268_yue38 dAFR_8268_yue39 dAFR_8268_yue40 dAFR_8268_yue41 dAFR_8268_yue42 dAFR_8268_yue43 dAFR_8268_yue44 dAFR_8268_yue45 dAFR_8268_yue46 dAFR_8268_yue47 dAFR_8268_yue48 dAFR_8268_yue49)


egen index_gui=rowtotal (dAFR_8268_gui15 dAFR_8268_gui16 dAFR_8268_gui17 dAFR_8268_gui18 dAFR_8268_gui19 dAFR_8268_gui20 dAFR_8268_gui21 dAFR_8268_gui22 dAFR_8268_gui23 dAFR_8268_gui24 dAFR_8268_gui25 dAFR_8268_gui26 dAFR_8268_gui27 dAFR_8268_gui28 dAFR_8268_gui29 dAFR_8268_gui30 dAFR_8268_gui31 dAFR_8268_gui32 dAFR_8268_gui33 dAFR_8268_gui34 dAFR_8268_gui35 dAFR_8268_gui36 dAFR_8268_gui37 dAFR_8268_gui38 dAFR_8268_gui39 dAFR_8268_gui40 dAFR_8268_gui41 dAFR_8268_gui42 dAFR_8268_gui43 dAFR_8268_gui44 dAFR_8268_gui45 dAFR_8268_gui46 dAFR_8268_gui47 dAFR_8268_gui48 dAFR_8268_gui49)


egen index_chuan=rowtotal (dAFR_8268_chuan15 dAFR_8268_chuan16 dAFR_8268_chuan17 dAFR_8268_chuan18 dAFR_8268_chuan19 dAFR_8268_chuan20 dAFR_8268_chuan21 dAFR_8268_chuan22 dAFR_8268_chuan23 dAFR_8268_chuan24 dAFR_8268_chuan25 dAFR_8268_chuan26 dAFR_8268_chuan27 dAFR_8268_chuan28 dAFR_8268_chuan29 dAFR_8268_chuan30 dAFR_8268_chuan31 dAFR_8268_chuan32 dAFR_8268_chuan33 dAFR_8268_chuan34 dAFR_8268_chuan35 dAFR_8268_chuan36 dAFR_8268_chuan37 dAFR_8268_chuan38 dAFR_8268_chuan39 dAFR_8268_chuan40 dAFR_8268_chuan41 dAFR_8268_chuan42 dAFR_8268_chuan43 dAFR_8268_chuan44 dAFR_8268_chuan45 dAFR_8268_chuan46 dAFR_8268_chuan47 dAFR_8268_chuan48 dAFR_8268_chuan49)

egen index_qian=rowtotal (dAFR_8268_qian15 dAFR_8268_qian16 dAFR_8268_qian17 dAFR_8268_qian18 dAFR_8268_qian19 dAFR_8268_qian20 dAFR_8268_qian21 dAFR_8268_qian22 dAFR_8268_qian23 dAFR_8268_qian24 dAFR_8268_qian25 dAFR_8268_qian26 dAFR_8268_qian27 dAFR_8268_qian28 dAFR_8268_qian29 dAFR_8268_qian30 dAFR_8268_qian31 dAFR_8268_qian32 dAFR_8268_qian33 dAFR_8268_qian34 dAFR_8268_qian35 dAFR_8268_qian36 dAFR_8268_qian37 dAFR_8268_qian38 dAFR_8268_qian39 dAFR_8268_qian40 dAFR_8268_qian41 dAFR_8268_qian42 dAFR_8268_qian43 dAFR_8268_qian44 dAFR_8268_qian45 dAFR_8268_qian46 dAFR_8268_qian47 dAFR_8268_qian48 dAFR_8268_qian49)

egen index_dian=rowtotal (dAFR_8268_dian15 dAFR_8268_dian16 dAFR_8268_dian17 dAFR_8268_dian18 dAFR_8268_dian19 dAFR_8268_dian20 dAFR_8268_dian21 dAFR_8268_dian22 dAFR_8268_dian23 dAFR_8268_dian24 dAFR_8268_dian25 dAFR_8268_dian26 dAFR_8268_dian27 dAFR_8268_dian28 dAFR_8268_dian29 dAFR_8268_dian30 dAFR_8268_dian31 dAFR_8268_dian32 dAFR_8268_dian33 dAFR_8268_dian34 dAFR_8268_dian35 dAFR_8268_dian36 dAFR_8268_dian37 dAFR_8268_dian38 dAFR_8268_dian39 dAFR_8268_dian40 dAFR_8268_dian41 dAFR_8268_dian42 dAFR_8268_dian43 dAFR_8268_dian44 dAFR_8268_dian45 dAFR_8268_dian46 dAFR_8268_dian47 dAFR_8268_dian48 dAFR_8268_dian49)


egen index_shaan=rowtotal (dAFR_8268_shaan15 dAFR_8268_shaan16 dAFR_8268_shaan17 dAFR_8268_shaan18 dAFR_8268_shaan19 dAFR_8268_shaan20 dAFR_8268_shaan21 dAFR_8268_shaan22 dAFR_8268_shaan23 dAFR_8268_shaan24 dAFR_8268_shaan25 dAFR_8268_shaan26 dAFR_8268_shaan27 dAFR_8268_shaan28 dAFR_8268_shaan29 dAFR_8268_shaan30 dAFR_8268_shaan31 dAFR_8268_shaan32 dAFR_8268_shaan33 dAFR_8268_shaan34 dAFR_8268_shaan35 dAFR_8268_shaan36 dAFR_8268_shaan37 dAFR_8268_shaan38 dAFR_8268_shaan39 dAFR_8268_shaan40 dAFR_8268_shaan41 dAFR_8268_shaan42 dAFR_8268_shaan43 dAFR_8268_shaan44 dAFR_8268_shaan45 dAFR_8268_shaan46 dAFR_8268_shaan47 dAFR_8268_shaan48 dAFR_8268_shaan49)


egen index_gansu=rowtotal (dAFR_8268_gansu15 dAFR_8268_gansu16 dAFR_8268_gansu17 dAFR_8268_gansu18 dAFR_8268_gansu19 dAFR_8268_gansu20 dAFR_8268_gansu21 dAFR_8268_gansu22 dAFR_8268_gansu23 dAFR_8268_gansu24 dAFR_8268_gansu25 dAFR_8268_gansu26 dAFR_8268_gansu27 dAFR_8268_gansu28 dAFR_8268_gansu29 dAFR_8268_gansu30 dAFR_8268_gansu31 dAFR_8268_gansu32 dAFR_8268_gansu33 dAFR_8268_gansu34 dAFR_8268_gansu35 dAFR_8268_gansu36 dAFR_8268_gansu37 dAFR_8268_gansu38 dAFR_8268_gansu39 dAFR_8268_gansu40 dAFR_8268_gansu41 dAFR_8268_gansu42 dAFR_8268_gansu43 dAFR_8268_gansu44 dAFR_8268_gansu45 dAFR_8268_gansu46 dAFR_8268_gansu47 dAFR_8268_gansu48 dAFR_8268_gansu49)

egen index_qinghai=rowtotal (dAFR_8268_qinghai15 dAFR_8268_qinghai16 dAFR_8268_qinghai17 dAFR_8268_qinghai18 dAFR_8268_qinghai19 dAFR_8268_qinghai20 dAFR_8268_qinghai21 dAFR_8268_qinghai22 dAFR_8268_qinghai23 dAFR_8268_qinghai24 dAFR_8268_qinghai25 dAFR_8268_qinghai26 dAFR_8268_qinghai27 dAFR_8268_qinghai28 dAFR_8268_qinghai29 dAFR_8268_qinghai30 dAFR_8268_qinghai31 dAFR_8268_qinghai32 dAFR_8268_qinghai33 dAFR_8268_qinghai34 dAFR_8268_qinghai35 dAFR_8268_qinghai36 dAFR_8268_qinghai37 dAFR_8268_qinghai38 dAFR_8268_qinghai39 dAFR_8268_qinghai40 dAFR_8268_qinghai41 dAFR_8268_qinghai42 dAFR_8268_qinghai43 dAFR_8268_qinghai44 dAFR_8268_qinghai45 dAFR_8268_qinghai46 dAFR_8268_qinghai47 dAFR_8268_qinghai48 dAFR_8268_qinghai49)



egen index_ning=rowtotal (dAFR_8268_ning15 dAFR_8268_ning16 dAFR_8268_ning17 dAFR_8268_ning18 dAFR_8268_ning19 dAFR_8268_ning20 dAFR_8268_ning21 dAFR_8268_ning22 dAFR_8268_ning23 dAFR_8268_ning24 dAFR_8268_ning25 dAFR_8268_ning26 dAFR_8268_ning27 dAFR_8268_ning28 dAFR_8268_ning29 dAFR_8268_ning30 dAFR_8268_ning31 dAFR_8268_ning32 dAFR_8268_ning33 dAFR_8268_ning34 dAFR_8268_ning35 dAFR_8268_ning36 dAFR_8268_ning37 dAFR_8268_ning38 dAFR_8268_ning39 dAFR_8268_ning40 dAFR_8268_ning41 dAFR_8268_ning42 dAFR_8268_ning43 dAFR_8268_ning44 dAFR_8268_ning45 dAFR_8268_ning46 dAFR_8268_ning47 dAFR_8268_ning48 dAFR_8268_ning49)


gen index_p=index_ning
replace index_p=index_dian  if p==2
replace index_p=index_qinghai  if p==30
replace index_p=index_gansu  if p==23
replace index_p=index_shaan if p==29
replace index_p=index_qian  if p==26
replace index_p=index_chuan  if p==6
replace index_p=index_gui  if p==13
replace index_p=index_yue  if p==12
replace index_p=index_xiang  if p==22
replace index_p=index_e  if p==21
replace index_p=index_henan  if p==18
replace index_p=index_lu  if p==10
replace index_p=index_gan  if p==16
replace index_p=index_min  if p==24
replace index_p=index_wan  if p==9
replace index_p=index_liao  if p==27
replace index_p=index_jilin if p==5
replace index_p=index_hei  if p==31
replace index_p=index_hu  if p==1
replace index_p=index_su  if p==15
replace index_p=index_zhe  if p==19
replace index_p=index_inner  if p==3
replace index_p=index_shan  if p==11
replace index_p=index_ji  if p==17
replace index_p=index_jin  if p==7
replace index_p=index_jing  if p==4

gen index_pr=-index_p
gen index_pr2=index_pr^2
gen index_pr3=index_pr^3


*other provincial convariates

gen rgdpper2018=gdpper2018*base/cpi
gen rgdpper2017=gdpper2017*base/cpi
gen rgdpper2015=gdpper2015*base/cpi
gen rgdpper2013=gdpper2013*base/cpi
gen rgdpper2012=gdpper2012*base/cpi
gen rgdpper2010=gdpper2010*base/cpi

gen rhp2018=hp2018*base/cpi
gen rhp2017=hp2017*base/cpi
gen rhp2015=hp2015*base/cpi
gen rhp2013=hp2013*base/cpi
gen rhp2012=hp2012*base/cpi
gen rhp2010=hp2010*base/cpi

gen rgdpper=rgdpper2018 if year==2018
replace rgdpper=rgdpper2017 if year==2017
replace rgdpper=rgdpper2015 if year==2015
replace rgdpper=rgdpper2013 if year==2013
replace rgdpper=rgdpper2012 if year==2012
replace rgdpper=rgdpper2010 if year==2010

gen popintense=popintense2018 if year==2018
replace popintense=popintense2017 if year==2017
replace popintense=popintense2015 if year==2015
replace popintense=popintense2013 if year==2013
replace popintense=popintense2012 if year==2012
replace popintense=popintense2010 if year==2010


gen unemployment=unemployment2018 if year==2018
replace unemployment=unemployment2017 if year==2017
replace unemployment=unemployment2015 if year==2015
replace unemployment=unemployment2013 if year==2013
replace unemployment=unemployment2012 if year==2012
replace unemployment=unemployment2010 if year==2010

*birth rate
gen brate=brate2018 if year==2018
replace brate=brate2018 if year==2017
replace brate=brate2018 if year==2015
replace brate=brate2018 if year==2013
replace brate=brate2018 if year==2012
replace brate=brate2018 if year==2010

gen rhp=rhp2018 if year==2018
replace rhp=rhp2017 if year==2017
replace rhp=rhp2015 if year==2015
replace rhp=rhp2013 if year==2013
replace rhp=rhp2012 if year==2012
replace rhp=rhp2010 if year==2010


*columns 1-3
reg rdensity index_pr index_pr2 index_pr3 rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)

reg rdensity index_pr index_pr2 rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)

reg rdensity index_pr rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)


*columns 4-5
reg penetration index_pr index_pr2 index_pr3 rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)

reg penetration index_pr index_pr2  rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)

reg penetration index_pr rgdpper rhp popintense unemployment brate i.year i.p if nn==1,clu(p)




************************
*********Robustness******** Table 6: Panel B+C & Table A.3 Panel B+C
************************

*Panel B
****keep predetermined controls only
ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.year i.p age   age2 age3  if sample_sc==1 , first clu(p) 
est store pre_sc

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.year i.p age   age2 age3 if sample_hc==1 , first clu(p) 
est store pre_hc

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.year i.p age   age2 age3 if sample_c==1 , first clu(p) 
est store pre_c

esttab pre_sc pre_hc pre_c,se star keep( children_have) b(%6.4f)  ar2(4) star(* 0.1 ** 0.05 *** 0.01) replace



*Panel C
******use Chen index
ivregress 2sls sinsurance_c (children_have=ffp_llpwife) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_sc==1, first clu(p) 
est store iv_s_cch

ivregress 2sls hinsurance_c (children_have=ffp_llpwife) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_hc==1, first clu(p) 
est store iv_h_cch

ivregress 2sls ins_c (children_have=ffp_llpwife) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sample_c==1, first clu(p) 
est store iv_cch

esttab iv_s_cch iv_h_cch iv_cch,se star keep( children_have) b(%6.4f)  ar2(4) star(* 0.1 ** 0.05 *** 0.01) replace




**********************************
***********Heterogeneity**********Table 7 + Table A.4
**********************************

*Panel A: Reliance on children
****************************************************
****whether rely on children for old-age support****
****************************************************


ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==1 &sample_sc==1, first clu(p) 

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==0&sample_sc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==1&sample_hc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==0 &sample_hc==1, first clu(p) 

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==1 &sample_c==1, first clu(p) 

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if rely_child1==0 &sample_c==1, first clu(p)



*Panel B: Social insurance status
*************************************************
****whether the respondent has public pension****
*************************************************


gen sins=1 if sinsurance==1
replace sins=0 if sinsurance==0


ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==1 &sample_sc==1, first clu(p) 

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==0&sample_sc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==1&sample_hc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==0 &sample_hc==1, first clu(p)

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==1 &sample_c==1, first clu(p) 

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if sins==0 &sample_c==1, first clu(p)




*Panel C: Rual/Urban 
**************************
********Rural/Urban*******
**************************

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 sah    if rural_hk==1&sample_sc==1, first clu(p) 

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3  sah    if rural_hk==0&sample_sc==1, first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 sah     if rural_hk==1&sample_hc==1, first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 sah     if rural_hk==0&sample_hc==1, first clu(p) 

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 sah    if rural_hk==1&sample_c==1, first clu(p)  

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 sah    if rural_hk==0&sample_c==1, first clu(p) 



*Panel D: House ownership
**********************
*own the house living*
**********************

gen ownhouse_living=1 if a121==1|a122==1
replace ownhouse_living=0 if ownhouse_living==.

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==1 &sample_sc==1, first clu(p) /

ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==0&sample_sc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==1&sample_hc==1 , first clu(p) 

ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==0 &sample_hc==1, first clu(p) 
est store nonownliving_hc


ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==1 &sample_c==1, first clu(p) 

ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if ownhouse_living==0 &sample_c==1, first clu(p)





**************************
*********Mechanism********Table 8
**************************

ivregress 2sls sah (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk  if totalsample==1, first clu(p)
est store sah

ivregress 2sls abnormal1 (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk  sah    if totalsample==1, first clu(p)
est store abnormal1

ivregress 2sls rinc_hh1 (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p  i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah    if totalsample==1, first clu( p)
est store inc_hh1 

ivregress 2sls interf (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah    if totalsample==1, first clu( p)
est store usef 







************************
*********Table 6******** robustness Panel D + Table A.3 Panel D
************************


clear all

set maxvar 30000

cap log use

clear all
cap log use

set maxvar 30000

use "/Users/cici/Desktop/CiCi/research/child and insurance/To demography/Aug04.dta"


drop if byr_spouse==.
gen age_spouse=year-byr_spouse
gen age_spouse2=age_spouse^2


gen age_wife=age if parent==1&male==0
replace age_wife=age_spouse if parent==1&male==1

gen age_hus=age if parent==1&male==1
replace age_hus=age_spouse if parent==1&male==0

*age restricions on parents
keep if age_wife>49
keep if parent==1

*remove obs with independent children who is below 18
gen indp_n=a68a
replace indp_n=a68b
replace indp_n=. if indp_n>20

gen withind=1 if indp_n>0&indp_n<=20
replace withind=0 if indp_n==0

drop if withind==1

*Keep if reside in hukou place
keep if hukou_local==1|hukou_local==2


gen edu_spouse=1 if a72>=1&a72<=4
replace edu_spouse=2 if a72>=5&a72<=8
replace edu_spouse=3 if a72>=9&a72<=14


gen byr_wife=byr if male==0
replace byr_wife=byr_spouse if male==1

gen ins_h=1 if hinsurance==1|hinsurance_c==1
replace ins_h=0 if hinsurance==0&hinsurance_c==0

gen ins_s=1 if sinsurance==1|sinsurance_c==1
replace ins_s=0 if sinsurance==0&sinsurance_c==0

*remove obs from minority ethnic groups
keep if han==1

drop if mari<0

*recode hukou type
gen rural_hk=1 if hukou_nong==1
replace rural_hk=1 if hukou_nong==3&year==2010
replace rural_hk=1 if hukou_nong==3&year==2013
replace rural_hk=1 if hukou_nong==3&year==2015
replace rural_hk=1 if hukou_nong==3&year==2017
replace rural_hk=1 if hukou_nong==3&year==2018
replace rural_hk=0 if hukou_nong==3&year==2012
replace rural_hk=0 if hukou_nong==4&year==2012
replace rural_hk=0 if hukou_nong==4&year==2010
replace rural_hk=0 if hukou_nong==4&year==2013
replace rural_hk=0 if hukou_nong==4&year==2015
replace rural_hk=0 if hukou_nong==4&year==2017
replace rural_hk=0 if hukou_nong==4&year==2018
replace rural_hk=0 if hukou_nong==2

*internet use frequency
gen interf=a285 if a285>=1&a285<=5


***abnormal BMI
gen height=a13 if a13>0&a13<200
gen w=a14 if a14>0&a14<300

gen bmi=0.5*w/((height/100)^2)

gen abnormal1=1 if bmi!=.&bmi>=25
replace abnormal1=1 if bmi!=.&bmi<18.5
replace abnormal1=0 if bmi>=18.5&bmi<25


*recode marital status
gen mari=1 if mari_raw==3
replace mari=1 if mari_raw==4
replace mari=2 if mari_raw==2
replace mari=3 if mari_raw==5

gen age3=age^3
gen age_spouse3 =age_spouse^3

gen rely_child1=1 if a41==2
replace rely_child1=0 if a41==1|a41==3|a41==4

gen manstronger= a422 if a422>=1&a422<=5

gen housen=a65 if a65>=0&a65<90


label var sinsurance_c "private pension"
label var hinsurance_c "private health insurance"
label var ins_c "private insurance"
label var sinsurance "public pension"
label var hinsurance "public health insurance"
label var p "province"
label var rural_hk "whether hold rural hukou"
label var rinc_hh1 "household income (log)"
label var sah "self-assessed health"
label var children_have "number of children"
label var rely_child1 "reliance on children for old-age"
label var manstronger "men superiority"
label var housen "number of houses"
label var interf "internet use frequency"




ivregress 2sls sinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   , first clu(p)
est store iv_s_cwf
estat firststage,forcenonrobust


ivregress 2sls hinsurance_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   , first clu(p) 
est store iv_h_cwf
estat firststage,forcenonrobust


ivregress 2sls ins_c (children_have=dffp_wife8268) male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   , first clu(p)
est store iv_cwf
estat firststage,forcenonrobust







******************************************
*********Supporting materials*************
******************************************


************************
*********Table A1******* Nonlinear model of Table 4
************************

*column 1
probit  rely_child1 dffp_wife8268 male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p)
est store rely_probit
margins, dydx(dffp_wife8268) predict(pr) 

*column 2
gen inter=housen*dffp_wife8268 

probit  rely_child1 dffp_wife8268 inter housen male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 
est store rely_probit
margins, dydx(dffp_wife8268 inter housen) predict(pr) 


*column 3
oprobit manstronger dffp_wife8268 male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,  vce(clu p)
margins, dydx(dffp_wife8268) predict(pr) 

*column 4
oprobit manstronger dffp_wife8268 inter housen male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,  vce(clu p) 
margins, dydx(dffp_wife8268 inter housen) predict(pr) 




************************
*********Table A2******* Vehicle ownership
************************

*whether own a private car
gen car=1 if a66==1
replace car=0 if a66==2


*column 1
reg  rely_child1 i.car##c.dffp_wife8268   male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 

*column 3
reg  manstronger i.car##c.dffp_wife8268   male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 


gen interaction1=car*dffp_wife8268

*column 2
probit  rely_child1 dffp_wife8268 interaction1 car male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,vce(clu p) 
est store rely_probit
margins, dydx(dffp_wife8268 interaction1 car) predict(pr) 

*column 4
oprobit manstronger dffp_wife8268 interaction1 car male i.edu i.edu_spouse i.year i.p rinc_hh1 i.mari age   age2 age3 age_spouse  age_spouse2  age_spouse3 rural_hk sah   if totalsample==1,  vce(clu p)
margins, dydx(dffp_wife8268 interaction1 car) predict(pr) 










